package com.buba.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.buba.feign.staffFeign;
import com.buba.mapper.PayrollMapper;
import com.buba.mapper.SchemeMapper;
import com.buba.service.PayrollService;
import entity.salary.Payroll;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import entity.salary.Scheme;
import entity.salary.dto.socialDto;
import entity.salary.vo.selPeopleSalaryInformationVo;
import entity.staff.Accounting;
import org.springframework.stereotype.Service;
import utils.PageResult;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author beisheng
 * @since 2023-03-14
 */
@Service
public class PayrollServiceImpl extends ServiceImpl<PayrollMapper, Payroll> implements PayrollService {

    @Resource
    private PayrollMapper payrollMapper;

    @Resource
    private staffFeign staffFeign;

    @Resource
    private SchemeMapper schemeMapper;
    /* *
     * @Author: beisheng
     * @Descriprion: 分页查询所有工资单
     * @Date: 2023/3/23 13:36
     * @Return: common.R
     * @Param: []
     */

    @Override
    public PageResult selAllPayroll(socialDto socialDto) {
        Page<Payroll> payrollPage = new Page<>(socialDto.getPage(),socialDto.getPagesize());
        Page<Payroll> payrollPages = payrollMapper.selectPage(payrollPage, new QueryWrapper<Payroll>().eq("delete_flag", 0));
        List<Payroll> payrollList = payrollMapper.selectList(new QueryWrapper<Payroll>().eq("delete_flag", 0));
        return new PageResult(socialDto.getPage(),socialDto.getPagesize(),payrollList.size(),payrollPages.getRecords());
    }

    /* *
     * @Author: beisheng
     * @Descriprion:查看所有工资单关联人员的薪资信息
     * @Date: 2023/3/23 16:13
     * @Return: common.R
     * @Param: [payRollId]
     */

    @Override
    public List<selPeopleSalaryInformationVo> selPeopleSalaryInformation(Integer payRollId) {
        List<selPeopleSalaryInformationVo> list = new ArrayList<>();
        //1.查询出当前关联薪资方案
        Payroll payroll = payrollMapper.selectOne(new QueryWrapper<Payroll>().eq("delete_flag", 0).eq("sa_id", payRollId));
        Scheme scheme = schemeMapper.selectOne(new QueryWrapper<Scheme>().eq("delete_flag", 0).eq("fa_id", payroll.getSchemeId()));
        List<String> selectorIds = Arrays.asList(scheme.getSelectors());
        //2.查询所有人员信息
        List<Accounting> accountings = staffFeign.selstaffByIds(selectorIds);
        //3.根据人员查询对应薪资

        //4.返回数据
        return list;
    }
}
